package oa.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import oa.bean.TSystem;
import oa.bean.TUser;
import oa.service.UserService;
import oa.util.SpringUtil;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

public class SessionInterceptor extends HandlerInterceptorAdapter {

	private TSystem syscfg = null;
	
	@Override
	public boolean preHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler) throws Exception {
		System.out.println("session interceptor");
		/*
		Object user = request.getSession().getAttribute("user");
		if(user == null) {
			response.sendRedirect(request.getContextPath()+"/adminlogin");
			return false;
		}
		//模拟用户
		TUser user = new TUser();
		user.setUserid(1);
		user.setUsername("admin");
		user.setOskey("admin");
		request.getSession().setAttribute("user", user);
		//
		*/
		if(syscfg == null) {
			UserService userService = SpringUtil.getBean("userService", UserService.class);
			syscfg = userService.getsystem();
		}
		request.setAttribute("syscfg", syscfg);
		return true;
	}

}
